<?php

namespace sms;

class Sms
{
    /**
     * 发送验证码
     * @param string $phoneNumber
     * @param string $type
     * @return void
     * @throws \Random\RandomException
     * @throws \ReflectionException
     */
    public static function sendCode(string $phoneNumber, string $type = SmsConfigEnum::ALI_SMS)
    {
        $code = random_int(10000, 99999);
        $classStats = ClassAttr::smsClassStat();
        /** @var SmsBase $classObj */
        $classObj = ClassAttr::initClass($type, $classStats);
        $sms = $classObj::sendCode($phoneNumber, $code);
        if ($sms) {
            cache(CacheSmsEnum::CODE_PRE . $phoneNumber, $code, CacheSmsEnum::CODE_EXPIRE);
        }
        return $sms;
    }
}